// 业务相关的工具方法
import store from '@/store/index';
import {
  PHOTO_TYPE, DANMU_TYPE, BAPIN_TYPE, SUPERDANMU_TYPE, POPUP_MODULE,
} from '../assets/constant/index';

// 格式化礼物列表
export const formatGiftList = (giftList) => {
  const result = [];
  let tempArr = [];

  for (let i = 0; i < giftList.length; i += 1) {
    tempArr.push({
      id: giftList[i].id,
      giftId: giftList[i].giftconst,
      name: giftList[i].giftname,
      giftImg: giftList[i].imglink,
      price: parseFloat(giftList[i].giftprice),
    });
    if ((i !== 0 && (i + 1) % 8 === 0) || i === giftList.length - 1) {
      result.push(tempArr);
      tempArr = [];
    }
  }
  return result;
};

// 格式化照片类型列表
export const formatPhotoTypeList = (photoTypeList) => {
  const result = [];
  for (let i = 0; i < photoTypeList.length; i += 1) {
    result.push({
      id: photoTypeList[i].id,
      giftId: photoTypeList[i].giftconst,
      name: PHOTO_TYPE[i].name,
      size: PHOTO_TYPE[i].size,
      price: parseFloat(photoTypeList[i].giftprice),
      time: photoTypeList[i].couponinfo,
    });
  }
  return result;
};

// 格式化霸气弹幕类型列表
export const formatDanmuTypeList = (danmuTypeList) => {
  const result = [];
  for (let i = 0; i < danmuTypeList.length; i += 1) {
    result.push({
      id: danmuTypeList[i].id,
      giftId: danmuTypeList[i].giftconst,
      name: DANMU_TYPE[i].name,
      size: DANMU_TYPE[i].size,
      wish: danmuTypeList[i].giftname,
      price: parseFloat(danmuTypeList[i].giftprice),
    });
  }
  return result;
};
// 格式化超级弹幕类型列表
export const formatSuperDanmuTypeList = (superDanmuTypeList) => {
  const result = [];
  for (let i = 0; i < superDanmuTypeList.length; i += 1) {
    result.push({
      id: superDanmuTypeList[i].id,
      giftId: superDanmuTypeList[i].giftconst,
      price: parseFloat(superDanmuTypeList[i].giftprice),
      time: superDanmuTypeList[i].shijian,
      giftname: SUPERDANMU_TYPE[i].name,
    });
  }
  return result;
};
// 格式化霸屏类型列表
export const formatBapinTypeList = (bapinTypeList) => {
  const result = [];
  for (let i = 0; i < bapinTypeList.length; i += 1) {
    result.push({
      id: bapinTypeList[i].id,
      giftId: bapinTypeList[i].giftconst,
      color: BAPIN_TYPE[i].color,
      colorCode: BAPIN_TYPE[i].colorCode,
      giftname: bapinTypeList[i].giftname,
      price: parseFloat(bapinTypeList[i].giftprice),
      shijian: bapinTypeList[i].shijian,
    });
  }
  return result;
};
export const formatBapinTypeList2 = (bapinTypeList) => {
  const result = [];
  for (let i = 0; i < bapinTypeList.length; i += 1) {
    result.push({
      id: bapinTypeList[i].id,
      giftId: bapinTypeList[i].giftconst,
      giftname: bapinTypeList[i].giftname,
      price: parseFloat(bapinTypeList[i].giftprice),
      shijian: bapinTypeList[i].shijian,
    });
  }
  return result;
};
// 通过gameCode获取游戏的一些常量
export const getGameInfoByGameCode = (gameCode) => {
  const gameInfo = {
    enterType: 'h5',
    gameUrl: '',
    needShake: false,
  };
  switch (gameCode) {
    case 'hmPlay3':
      // 扭一扭
      gameInfo.enterType = 'mp';
      gameInfo.gameUrl = `/pages/nyn/nyn?userId=${store.state.user.userId}&openId=${store.state.user.openId}&name=${store.state.user.name}&headImg=${store.state.user.headImg}`;
      gameInfo.needShake = false;
      break;
    case 'hmPlay4':
      // 转一转
      gameInfo.enterType = 'mp';
      gameInfo.gameUrl = `/pages/zyz/zyz?userId=${store.state.user.userId}&openId=${store.state.user.openId}&zyzList=${store.state.live.zyzList}&name=${store.state.user.name}&headImg=${store.state.user.headImg}`;
      gameInfo.needShake = false;
      break;
    case 'hmPlay21':
      // 谁与争锋
      gameInfo.enterType = 'mp';
      gameInfo.gameUrl = `/pages/diceGameNew/diceGameNew?userId=${store.state.user.userId}&openId=${store.state.user.openId}&beerJson=${store.state.live.beerJson}`;
      gameInfo.needShake = false;
      break;
    case 'hmPlay22':
      // 点数风暴
      gameInfo.enterType = 'mp';
      gameInfo.gameUrl = `/pages/pointStorm/pointStorm?userId=${store.state.user.userId}&openId=${store.state.user.openId}`;
      gameInfo.needShake = false;
      break;
    case 'hmPlay1':
      // 红包雨
      gameInfo.enterType = 'h5';
      gameInfo.gameUrl = '/hby';
      gameInfo.needShake = true;
      break;
    case 'hmPlay6':
      // 摇一摇
      gameInfo.enterType = 'h5';
      gameInfo.gameUrl = '/shake';
      gameInfo.needShake = true;
      break;
    case 'hmPlay8':
      // 谁最牛
      gameInfo.enterType = 'h5';
      gameInfo.gameUrl = '/cattleShake';
      gameInfo.needShake = true;
      break;
    case 'hmPlay7':
      // 数钞票
      gameInfo.enterType = 'h5';
      gameInfo.gameUrl = '/countMoney';
      gameInfo.needShake = false;
      break;
    case 'hmPlay9':
      // 切水果
      gameInfo.enterType = 'h5';
      gameInfo.gameUrl = '/cutFruit';
      gameInfo.needShake = false;
      break;
    case 'hmPlay2':
      // 开宝箱
      gameInfo.enterType = 'mp';
      gameInfo.gameUrl = `/pages/kbx/kbx?userId=${store.state.user.userId}&openId=${store.state.user.openId}&name=${store.state.user.name}&headImg=${store.state.user.headImg}`;
      gameInfo.needShake = false;
      break;
    case 'hmPlay5':
      // 红包墙
      gameInfo.enterType = 'mp';
      gameInfo.gameUrl = `/pages/hbWall/hbWall?userId=${store.state.user.userId}&openId=${store.state.user.openId}&name=${store.state.user.name}&headImg=${store.state.user.headImg}`;
      gameInfo.needShake = false;
      break;
    case 'vote':
      // 投票
      gameInfo.enterType = 'h5';
      gameInfo.gameUrl = '/vote';
      gameInfo.needShake = false;
      break;
    case 'hmPlay10':
      // 手写签名
      gameInfo.enterType = 'h5';
      gameInfo.gameUrl = '/bubbleSign';
      gameInfo.needShake = false;
      break;
    case 'hmPlay11':
      // 点红包
      gameInfo.enterType = 'h5';
      gameInfo.gameUrl = '/clickHb';
      gameInfo.needShake = false;
      break;
    case 'hmPlay20':
      // 踢足球
      gameInfo.enterType = 'h5';
      gameInfo.gameUrl = '/playFootball';
      gameInfo.needShake = false;
      break;
    case 'hmPlay23':
      // 许愿树抽奖
      gameInfo.enterType = 'h5';
      gameInfo.gameUrl = '/wishTreeLottery';
      gameInfo.needShake = false;
      break;
    case 'hmPlay24':
      // 对对碰
      gameInfo.enterType = 'h5';
      gameInfo.gameUrl = '/duiduipeng';
      gameInfo.needShake = false;
      break;
    default:
      gameInfo.enterType = 'h5';
      gameInfo.gameUrl = '我是默认地址';
      gameInfo.needShake = false;
  }
  return gameInfo;
};

// 根据key查找弹出模块
export const getPopModuleByKey = (key) => {
  const moduleKeys = Object.keys(POPUP_MODULE);
  const tmpLen = moduleKeys.length;
  let tmpResult = null;
  for (let i = 0; i < tmpLen; i += 1) {
    if (POPUP_MODULE[moduleKeys[i]].key === key) {
      tmpResult = POPUP_MODULE[moduleKeys[i]];
      break;
    }
  }
  return tmpResult;
};
